package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 向文件中写出文本数据
 */
public class WriteStringDemo {
    public static void main(String[] args) throws IOException {
        //需求：向文件for.txt中写出字符串
        FileOutputStream fos = new FileOutputStream("for.txt");
        String line = "一袋米要扛几楼";

        byte[] data = line.getBytes(StandardCharsets.UTF_8);//文字转字符就是这样 要有这一步
        fos.write(data);

        line = "滚筒洗衣机";
        data = line.getBytes(StandardCharsets.UTF_8);
        fos.write(data);

        System.out.println("输出完毕");
        fos.close();



    }
}
